package net.cc.jsy.controller;

import net.cc.jsy.entity.BaseHttpResult;
import net.cc.jsy.entity.ReqEntity;
import net.cc.jsy.service.MdbDbInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 *
 * @author jingshiyu
 *
 * @date 2021.11.16 14:21:17
 *
 * @desc
 */
@RequestMapping("/")
@RestController
public class MdbController {
    public static final String FAIL = "_fail";
    public static final String SUCCESS = "_success";
    @Autowired
    private MdbDbInfoService service;

    @RequestMapping("/export1")
    public BaseHttpResult<?> export(@RequestBody ReqEntity entity) throws Exception {
        if (StringUtils.isBlank(entity.getPath())) {
            return fail("文件地址不能为空");
        } else if (StringUtils.isBlank(entity.getOutPath())) {
            return fail("导出地址不能为空");
        }

        service.exportDate(entity.getPath(), entity.getOutPath(), entity.getTableName());
        return success("成功");
    }

    public BaseHttpResult<?> fail(String hint) {
        return new BaseHttpResult<>(false, FAIL, hint, null);
    }

    public BaseHttpResult<?> success(String hint) {
        return new BaseHttpResult<>(true, SUCCESS, hint, null);
    }
}
